import 'package:shared_preferences/shared_preferences.dart';

///
/// 键值对存储通用工具
///
///
class KVDataUtils {
  KVDataUtils.getInstance();

  static late SharedPreferences _spf;

  Future<SharedPreferences> init() async {
    _spf = await SharedPreferences.getInstance();
    return _spf;
  }

  Future<SharedPreferences> asyncInit() {
    return SharedPreferences.getInstance();
  }

  ///
  String? getString(String key) {
    return _spf.getString(key);
  }

  ///
  Future<bool> setString(String key, String value) {
    return _spf.setString(key, value);
  }

  Future<bool> removeKey(String key) {
    return _spf.remove(key);
  }

  ///
  int? getInt(String key) {
    var v = _spf.getInt(key);
    return v;
  }

  ///
  Future<bool> setInt(String key, int value) {
    return _spf.setInt(key, value);
  }

  ///
  bool? getBool(String key) {
    return _spf.getBool(key);
  }

  ///
  Future<bool> setBool(String key, bool value) {
    return _spf.setBool(key, value);
  }

  bool containsKey(String s) {
    return _spf.containsKey(s);
  }

  Future<bool> clear() {
    return _spf.clear();
  }
}
